package com.css.bjdt_core.report.service;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.css.bjdt_core.report.entity.RptAreaCategoryR;
import com.css.bjdt_core.util.CommonUtil;

@Service
public class RptAreaCategoryRService {
	@Autowired
	private Dao dao;

	//保存报表区域和数据集之间的关系
	public void saveRptAreaCategoryR(String areaId, String categoryId) {
		RptAreaCategoryR rptAreaCategoryR = new RptAreaCategoryR();
		rptAreaCategoryR.setId(CommonUtil.getUUID());
		rptAreaCategoryR.setAreaId(areaId);
		rptAreaCategoryR.setCategoryId(categoryId);
		dao.insert(rptAreaCategoryR);
	}

	//删除报表报表区域和数据集之间的关系
	public void deleteRptAreaCategoryR(String areaId) {
		dao.clear(RptAreaCategoryR.class, Cnd.where("AREA_ID", "=", areaId));
	}

	//通过报表区域的ID，找到对应的数据集区域
	public String getCategoryIdByAreaId(String areaId) {
		RptAreaCategoryR rptAreaCategoryR = dao.fetch(RptAreaCategoryR.class, Cnd.where("AREA_ID", "=", areaId));
		if (rptAreaCategoryR != null) {
			return rptAreaCategoryR.getCategoryId();
		} else {
			return null;
		}
	}
}
